home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Draw / Sources / BoundShp.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  7.4 KB  |  305 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                BoundShp.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef UTILS_H
  23. #include "Utils.h"
  24. #endif
  25.  
  26. #ifndef CONSTANT_H
  27. #include "Constant.h"
  28. #endif
  29.  
  30. #ifndef DRAWPART_H
  31. #include "DrawPart.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWFRM_H
  39. #include "DrawFrm.h"
  40. #endif
  41.  
  42. #ifndef DRAWPRXY_H
  43. #include "DrawPrxy.h"
  44. #endif
  45.  
  46. #ifndef DRAWLINK_H
  47. #include "DrawLink.h"
  48. #endif
  49.  
  50. #ifndef DRAWCLIP_H
  51. #include "DrawClip.h"
  52. #endif
  53.  
  54. // ----- Part Layer -----
  55.  
  56. #ifndef FWFRMING_H
  57. #include "FWFrming.h"
  58. #endif
  59.  
  60. #ifndef FWUTIL_H
  61. #include "FWUtil.h"
  62. #endif
  63.  
  64. #ifndef FWSELECT_H
  65. #include "FWSelect.h"
  66. #endif
  67.  
  68. #ifndef FWITERS_H
  69. #include "FWIters.h"
  70. #endif
  71.  
  72. // ----- OS Layer -----
  73.  
  74. #ifndef FWEVENT_H
  75. #include "FWEvent.h"
  76. #endif
  77.  
  78. #ifndef FWRECSHP_H
  79. #include "FWRecShp.h"
  80. #endif
  81.  
  82. #ifndef FWTXTBOX_H
  83. #include "FWTxtBox.h"
  84. #endif
  85.  
  86. #ifndef FWLINSHP_H
  87. #include "FWLinShp.h"
  88. #endif
  89.  
  90. #ifndef FWOVLSHP_H
  91. #include "FWOvlShp.h"
  92. #endif
  93.  
  94. #ifndef FWRRCSHP_H
  95. #include "FWRRcShp.h"
  96. #endif
  97.  
  98. #ifndef FWODGEOM_H
  99. #include "FWODGeom.h"
  100. #endif
  101.  
  102. // ----- OpenDoc Includes -----
  103.  
  104. #ifndef SOM_ODTransform_xh
  105. #include <Trnsform.xh>
  106. #endif
  107.  
  108. //========================================================================================
  109. // Runtime Information
  110. //========================================================================================
  111.  
  112. #ifdef FW_BUILD_MAC
  113. #pragma segment odfdrawshapes
  114. #endif
  115.  
  116. //========================================================================================
  117. // RunTime Info
  118. //========================================================================================
  119.  
  120. FW_DEFINE_CLASS_M1(CBoundedShape, CBaseShape)
  121.  
  122. //========================================================================================
  123. // class CBoundedShape
  124. //========================================================================================
  125.  
  126. //----------------------------------------------------------------------------------------
  127. // CBoundedShape::CBoundedShape
  128. //----------------------------------------------------------------------------------------
  129.  
  130. CBoundedShape::CBoundedShape(unsigned short shapeType, unsigned short renderVerb) :
  131.     CBaseShape(4, shapeType, renderVerb)
  132. {
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. // CBoundedShape::CBoundedShape
  137. //----------------------------------------------------------------------------------------
  138.  
  139. CBoundedShape::CBoundedShape(FW_CReadableStream& archive) :
  140.     CBaseShape(archive)
  141. {    
  142.     archive >> fRect;
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. // CBoundedShape::~CBoundedShape
  147. //----------------------------------------------------------------------------------------
  148.  
  149. CBoundedShape::~CBoundedShape()
  150. {
  151. }
  152.  
  153. //----------------------------------------------------------------------------------------
  154. // CBoundedShape::GetHandleCenter
  155. //----------------------------------------------------------------------------------------
  156.  
  157. void CBoundedShape::GetHandleCenter(short whichHandle, FW_CPoint& center) const
  158. {    
  159.     switch (whichHandle)
  160.     {
  161.         case kInTopLeftCorner:
  162.             center.x = fRect.left;
  163.             center.y = fRect.top;
  164.             break;
  165.         case kInTopRightCorner:
  166.             center.x = fRect.right;
  167.             center.y = fRect.top;
  168.             break;
  169.         case kInBottomLeftCorner:
  170.             center.x = fRect.left;
  171.             center.y = fRect.bottom;
  172.             break;
  173.         case kInBottomRightCorner:
  174.             center.x = fRect.right;
  175.             center.y = fRect.bottom;
  176.             break;
  177.     }
  178. }
  179.  
  180. //----------------------------------------------------------------------------------------
  181. // CBoundedShape::ResizeFeedback
  182. //----------------------------------------------------------------------------------------
  183.  
  184. void CBoundedShape::ResizeFeedback(FW_CGraphicContext& gc, const FW_PInk& ink, const FW_PStyle& style, 
  185.                                     short whichHandle, const FW_CPoint& mouseLoc)
  186. {
  187.     FW_CRect srcRect, dstRect;
  188.     GetMapRects(whichHandle, mouseLoc, srcRect, dstRect);
  189.     dstRect.Sort();
  190.     OutlineShape(gc, ink, style, dstRect);
  191. }
  192.  
  193. //----------------------------------------------------------------------------------------
  194. // CBoundedShape::GetMapRects
  195. //----------------------------------------------------------------------------------------
  196.  
  197. void CBoundedShape::GetMapRects(short whichHandle, const FW_CPoint& mouseLoc,
  198.                                 FW_CRect& srcRect, FW_CRect& dstRect)
  199. {
  200.     srcRect = fRect;
  201.     dstRect = srcRect;
  202.     
  203.     switch (whichHandle)
  204.     {
  205.         case kInTopLeftCorner:
  206.             dstRect.left = mouseLoc.x;
  207.             dstRect.top = mouseLoc.y;
  208.             break;
  209.         case kInTopRightCorner:
  210.             dstRect.right = mouseLoc.x;
  211.             dstRect.top = mouseLoc.y;
  212.             break;
  213.         case kInBottomLeftCorner:
  214.             dstRect.left = mouseLoc.x;
  215.             dstRect.bottom = mouseLoc.y;
  216.             break;
  217.         case kInBottomRightCorner:
  218.             dstRect.right = mouseLoc.x;
  219.             dstRect.bottom = mouseLoc.y;
  220.             break;
  221.     }
  222. }
  223.  
  224. //----------------------------------------------------------------------------------------
  225. // CBoundedShape::MapShape
  226. //----------------------------------------------------------------------------------------
  227.  
  228. void CBoundedShape::MapShape(Environment *ev, CDrawPart* part, const FW_CRect& srcRect, const FW_CRect& dstRect)
  229. {
  230.     CheckPromise(ev, part);
  231.     
  232.     ClearCache();
  233.  
  234.     fRect.Map(srcRect, dstRect);    
  235.     fRect.Sort();
  236. }
  237.  
  238. //----------------------------------------------------------------------------------------
  239. // CBoundedShape::OffsetShape
  240. //----------------------------------------------------------------------------------------
  241.  
  242. void CBoundedShape::OffsetShape(Environment *ev, FW_CFixed xDelta, FW_CFixed yDelta)
  243. {
  244.     ClearCache();
  245.     fRect.Offset(xDelta, yDelta);
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. // CBoundedShape::SetShapeGeometry
  250. //----------------------------------------------------------------------------------------
  251.  
  252. void CBoundedShape::SetShapeGeometry(const FW_CPoint& anchorPoint,  const FW_CPoint& currentPoint)
  253. {
  254.     if (anchorPoint.x < currentPoint.x)
  255.     {
  256.         fRect.left = anchorPoint.x;
  257.         fRect.right = currentPoint.x;
  258.     }
  259.     else
  260.     {
  261.         fRect.left = currentPoint.x;
  262.         fRect.right = anchorPoint.x;
  263.     }
  264.     
  265.     if (anchorPoint.y < currentPoint.y)
  266.     {
  267.         fRect.top = anchorPoint.y;
  268.         fRect.bottom = currentPoint.y;
  269.     }
  270.     else
  271.     {
  272.         fRect.top = currentPoint.y;
  273.         fRect.bottom = anchorPoint.y;
  274.     }
  275. }
  276.  
  277. //----------------------------------------------------------------------------------------
  278. // CBoundedShape::Flatten
  279. //----------------------------------------------------------------------------------------
  280.  
  281. void CBoundedShape::Flatten(FW_CWritableStream& archive)
  282. {    
  283.     CBaseShape::Flatten(archive);
  284.     archive << fRect;
  285. }
  286.  
  287. //----------------------------------------------------------------------------------------
  288. // CBoundedShape::SetRectGeometry
  289. //----------------------------------------------------------------------------------------
  290.  
  291. void CBoundedShape::SetRectGeometry(const FW_CRect& bounds)
  292. {
  293.     fRect = bounds;
  294. }
  295.     
  296. //----------------------------------------------------------------------------------------
  297. // CBoundedShape::GetRectGeometry
  298. //----------------------------------------------------------------------------------------
  299.  
  300. void CBoundedShape::GetRectGeometry(FW_CRect& bounds) const
  301. {
  302.     bounds = fRect;
  303. }
  304.  
  305.